package be.kuleuven.mume.paginas;

import java.util.List;

import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import be.kuleuven.mume.R;
import be.kuleuven.mume.framework.Persoon;
import be.kuleuven.mume.framework.Vak;
import be.kuleuven.mume.hulpklassen.DataFetcher;
import be.kuleuven.mume.hulpklassen.JSONParser.PersoonParser;
import be.kuleuven.mume.hulpklassen.RetainListActivity;
import be.kuleuven.mume.listProxys.LastCellLoadingProxy;

public class VakStudentenTab extends RetainListActivity<Persoon>{
	private List<Persoon> studenten;
	private ArrayAdapter<Persoon> adapter;
	private LastCellLoadingProxy loadingProxy;
	private DataFetcher<Persoon> dataFetcher;
	private Vak vak;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.vak_studenten);
		
    	studenten = this.getItems();
    	
    	Bundle extras = getIntent().getExtras();
    	vak = (Vak)extras.get("VAK");
    	
    	String url = Vak.getStudentenURL(vak.getVakId());
    	
    	ListView table = (ListView)findViewById(R.id.studenten_table);
    	adapter = new ArrayAdapter<Persoon>(this, R.layout.rij_simpel, studenten);
    	
    	loadingProxy = new LastCellLoadingProxy(adapter);
    	loadingProxy.noDataString_ID = R.string.geen_studenten;
    	
    	table.setAdapter(loadingProxy);
    	
    	PersoonParser parser = new PersoonParser();
    	dataFetcher = new DataFetcher<Persoon>(parser, url, table, studenten, this.getBaseContext()){
    		public void DataReceived(){
    			if(!dataFetcher.hasMoreData())
    				loadingProxy.setIsLoading(false);
    			adapter.notifyDataSetChanged();
    		}
    	};
	}
	
	
}
